<template>
  <div style="height: 100%; width: 100%; position: relative" ref="maindev">
      <div class="pagetop">
          <div style="width: 100%">
              <table style="font-size: 12px; white-space: nowrap" border="0" class="table1style">
                  <tr>
                      <td align="right">生成时间</td>
                      <td style="width: 280px">
                          <table style="border-spacing: 0px; width: 100%">
                              <tr>
                                  <td style="padding: 0px">
                                      <el-date-picker v-model="txtstartdate" :clearable="false" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" style="width: 100%"> </el-date-picker>
                                  </td>
                                  <td>至</td>
                                  <td style="padding: 0px">
                                      <el-date-picker v-model="txtenddate" type="date" :clearable="false" placeholder="选择日期" value-format="yyyy-MM-dd" style="width: 100%"> </el-date-picker>
                                  </td>
                              </tr>
                          </table>
                      </td>
                      <td align="right">科室</td>
                      <td>
                          <el-select v-model="txtreqdeptno" @dblclick.native="popMultipleChk(txtreqdeptno, 'txtreqdeptno', deptOption, '申请科室选择')" filterable clearable style="width: 100%">
                              <el-option v-for="(item, index) in deptOption" :key="index" :value="item.data" :label="item.display"> </el-option>
                          </el-select>
                      </td>
                      <td align="right">病人类型</td>
                      <td>
                          <rm-ddl-common v-model="txtpattype" datatype="seccode" kindno="PT" dataname="病人类型" @change="seccodeChange" width="200px" key="pt"></rm-ddl-common>
                      </td>
                      <td>标本类型</td>
                      <td>
                          <rm-ddl-common v-model="txtspecimencode" datatype="specimen" :appendtobody="true" width="100%" ref="inputspec" @change="specimenChange"></rm-ddl-common>
                      </td>
                      <td style="width: 80px"></td>
                      <td style="width: 80px"></td>
                      <td style="width: 80px"></td>
                  </tr>
                  <tr>
                      <td align="right">分单类别</td>
                      <td style="width: 280px">
                          <rm-ddl-common v-model="txtreqgroupid" @change="reqgroupChange" datatype="reqgroup" dataname="分单类别" width="280px"></rm-ddl-common>
                      </td>
                      <td align="right">病区</td>
                      <td>
                          <el-select v-model="txtwardno" @dblclick.native="popMultipleChk(txtwardno, 'txtwardno', wardOption, '病区选择')" filterable clearable style="width: 100%">
                              <el-option v-for="(item, index) in wardOption" :key="index" :value="item.data" :label="item.display"> </el-option>
                          </el-select>
                      </td>
                      <td align="right">标本归类</td>
                      <td>
                          <el-select v-model="txtspecimentype" style="width: 100%" clearable>
                              <el-option v-for="item in specimentypeOption" :key="item.data" :label="item.display" :value="item.data"></el-option>
                          </el-select>
                      </td>
                      <td colspan="2"><el-checkbox v-model="txtemergency" true-label="1" false-label="0">急诊</el-checkbox></td>
                      <td></td>
                      <td></td>
                      <td></td>
                  </tr>
                  <tr>
                      <td>统计类型</td>
                      <td><el-checkbox true-label="1" false-label="0" v-model="issample">采样</el-checkbox></td>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                  </tr>
                  <tr>
                      <td>统计项目</td>
                      <td colspan="10" align="left">
                          <div class="mychkclass">
                              <el-checkbox v-model="chklist.chk_req_deptno" true-label="1" false-label="0" @change="chkevent($event, 'chk_req_deptname', '科室')">申请科室</el-checkbox>
                              <el-checkbox v-model="chklist.chk_req_wardno" true-label="1" false-label="0" @change="chkevent($event, 'chk_req_wardname', '病区')">病区</el-checkbox>
                              <el-checkbox v-model="chklist.chk_pat_typecode" true-label="1" false-label="0" @change="chkevent($event, 'chk_pat_typename', '病人类型')">病人类型</el-checkbox>
                              <el-checkbox v-model="chklist.chk_req_groupid" true-label="1" false-label="0" @change="chkevent($event, 'chk_req_groupname', '分单类别')">分单类别</el-checkbox>
                              <el-checkbox v-model="chklist.chk_specimen_code" true-label="1" false-label="0" @change="chkevent($event, 'chk_specimen_name', '标本类型')">标本类型</el-checkbox>
                              <el-checkbox v-model="chklist.chk_emer_flag" true-label="1" false-label="0" @change="chkevent($event, 'chk_emer_flagname', '急诊')">急诊</el-checkbox>
                              <el-checkbox v-model="chklist.chk_years" true-label="1" false-label="0" @change="chkevent($event, 'chk_years', '年')">年</el-checkbox>
                              <el-checkbox true-label="1" false-label="0" v-model="chklist.chk_months" @change="chkevent($event, 'chk_months', '月')">月</el-checkbox>
                              <el-checkbox true-label="1" false-label="0" v-model="chklist.chk_days" @change="chkevent($event, 'chk_days', '日')">日</el-checkbox>
                          </div>
                      </td>
                  </tr>
              </table>
              <div class="operation-list">
                  <el-button @click.native="BtnQuery" v-has="'PINQUERY'" type="primary" icon="el-icon-search">查询</el-button>
                  <el-button @click.native="BtnClear" icon="el-icon-close">清除</el-button>
                  <el-button @click.native="BtnExport" icon="el-icon-download">导出</el-button>
                  <!-- <el-button @click.native="BtnPrint(1)" v-has="'PPRINT'" icon="el-icon-printer">打印</el-button> -->
              </div>
          </div>
      </div>
      <div class="pagecenter">
          <div class="middle-center">
              <vxe-table :data.sync="tableData" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row class="mytable-style" highlight-hover-column highlight-hover-row how-header-overflow ref="xTable" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{ animat: false }" header-align="center" :key="xTablekey" show-footer :footer-method="footerMethod" :footer-cell-class-name="footerCellClassName" :loading="xTableLoading" @cell-dblclick="rCellDblClick">
                  <vxe-table-column type="index" title="NO." width="50" header-align="center" align="center"></vxe-table-column>
                  <vxe-table-column :field="items.field" :key="items.field" :title="items.title" :width="items.width" sortable v-for="items in tableColumn" ></vxe-table-column>
                  <vxe-table-column field="cp_samplecnt" title="标本数" sortable width="70" header-align="center" align="right"></vxe-table-column>
                  <vxe-table-column field="cp_okcnt" title="记录采样时间数" sortable width="120" header-align="center" align="right" v-if="issample == '1'"></vxe-table-column>
                  <vxe-table-column field="cp_okrate" title="记录采样时间率" sortable width="120" header-align="center" align="right" v-if="issample == '1'"></vxe-table-column>
                  <vxe-table-column field="cp_nocnt" title="无采样时间数" sortable width="100" header-align="center" align="right" v-if="issample == '1'">
                      <template v-slot="{ row }">
                          <div style="color: blue; cursor: pointer">
                              <u>{{ row.cp_nocnt }}</u>
                          </div>
                      </template>
                  </vxe-table-column>
                  <vxe-table-column field="cp_norate" title="无采样时间率" sortable width="100" header-align="center" align="right" v-if="issample == '1'"></vxe-table-column>
              </vxe-table>
          </div>
      </div>

      <!--多选弹窗--->
      <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="multichktitle" :visible.sync="dialogMultipleVisible" :destroy-on-close="true">
          <rm-SqlMultiple :leftOption="option1" :rightOption="option2" :name="fieldname" @change="closedialog"></rm-SqlMultiple>
      </el-dialog>
      <el-dialog width="1100px" title="无采样时间申请单明细查看" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="dialogDetailVisible" :destroy-on-close="true">
          <div style="height: 500px; width: 100%">
              <rm-layout-left splitcolor="#ffffff" :splitwidth="2" :fixsize="675" :minfixsize="200" ref="layoutright">
                  <template v-slot:fix>
                      <div style="height: 100%">
                          <vxe-table ref="reqtable" :data.sync="reqtabledata" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow resizable show-overflow size="mini" show-header-overflow :optimization="{ animat: false }" @current-change="reqchange_Event" header-align="center">
                              <vxe-table-column type="index" title="No." width="35" align="center"></vxe-table-column>
                              <vxe-table-column :field="items.field" :key="items.field" :title="items.title" :width="items.width" sortable v-for="items in reqtableColumn"></vxe-table-column>
                          </vxe-table>
                      </div>
                  </template>
                  <div style="height: 100%">
                      <vxe-table ref="reqdetailtable" :data.sync="reqdetailtabledata" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow resizable show-overflow size="mini" show-header-overflow :optimization="{ animat: false }" header-align="center">
                          <vxe-table-column :field="items.field" :key="items.field" :title="items.title" :width="items.width" sortable v-for="items in reqdetailColumn"></vxe-table-column>
                      </vxe-table>
                  </div>
              </rm-layout-left>
          </div>
      </el-dialog>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
  name: "LIS623",
  data() {
      return {
          chklist: {},
          dialogMultipleVisible: false,
          dialogdetailVisible: false,
          xTableLoading: false,
          option1: [],
          option2: [],
          fieldname: "",
          tableColumn: [],
          tableData: [],
          currRowIndex: 0,
          xTablekey: 0,
          multichktitle: "",
          pattypeOption: [],
          deptOption: [],
          wardOption: [],
          doctorOption: [],
          specimentypeOption: [],
          issample: "1", // 默认采样
          //以下为查询条件
          txtstartdate: "", // 生成日期
          txtenddate: "", //生成日期
          txtreqdeptno: "", // 申请 科室
          txtpattype: "", // 病人类型
          txtspecimencode: "", //标本类型
          txtreqgroupid: "", // 分单类别
          txtwardno: "", // 病区
          txtspecimentype: "", // 标本归类
          txtemergency: "", // 急诊

          //以下为统计项目
          chklist: {
              chk_req_deptno: false,
              chk_req_wardno: false,
              chk_pat_typecode: false,
              chk_req_groupid: false,
              chk_specimen_code: false,
              chk_emer_flag: false,
              chk_years: false,
              chk_months: false,
              chk_days: false,
          },
          infocode: "",
          infoitem: "",
          userno: this.$tool.getSession(this.$tool.loginuserno),
          chkcnt: 0,
          selrow: [],
          dialogDetailVisible: false,
          reqtableColumn: [],
          reqdetailColumn: [],
          reqtabledata: [],
          reqdetailtabledata: [],
          exportTableColLen: 0,
          specimenname: "",
          reqgroupname: "",
          pattypename: "",
      };
  },
  created() {
      this.initOption();
      this.initdate(); //初始化时间
  },
  mounted() {},
  updated() {},
  methods: {
      popMultipleChk(e, fieldname, option, title) {
          let temp = XEUtils.clone(option, true);
          this.option1 = [];
          this.option2 = [];
          if (e != "") {
              let k = e.split(",");
              k.forEach((item) => {
                  let ndata = temp.find((m) => m.data == item);
                  if (ndata != undefined && ndata != null) {
                      this.option2.push(ndata);
                  }
              });
              temp.forEach((item) => {
                  if (k.indexOf(item.data + "") < 0) {
                      this.option1.push(item);
                  }
              });
          } else {
              this.option1 = temp;
          }
          this.fieldname = fieldname;
          this.multichktitle = title;
          this.dialogMultipleVisible = true;
      },
      closedialog(value, name) {
          if (value != "close") {
              this[name] = value;
          }
          this.dialogMultipleVisible = false;
      },
      //时间初始化
      initdate() {
          this.txtstartdate = this.$pub.InitDateTime();
          this.txtenddate = this.$pub.InitDateTime();
          this.txttimevalue = [new Date(2016, 9, 10, 0, 0), new Date(2016, 9, 10, 23, 59)];
      },
      currentChangeEvent1({ row, $rowIndex }) {
          this.currRowIndex = $rowIndex;
      },
      async initOption() {
          try {
              const res = await this.$tool.request({
                  url: "LIS/LIS6/LIS623",
                  method: "post",
                  data: {
                      action: "initOption",
                  },
              });
              //this.pattypeOption = res.pattypeOption;
              this.deptOption = res.deptOption;
              this.wardOption = res.wardOption;
              //this.specimenOption = res.specimenOption;
              this.specimentypeOption = res.specimentypeOption;
              //this.reqgroupOption = res.reqgroupOption;
          } catch (e) {
              this.$message.warning(e);
          }
      },
      BtnQuery() {
          this.InitPage();
      },
      async InitPage() {
          try {
              if (this.chkcnt < 1) {
                  this.$alert("请勾选右边分组条件！", "信息");
                  return false;
              }
              this.xTableLoading = true;
              const response = await this.$tool.request({
                  url: "LIS/LIS6/LIS623",
                  method: "post",
                  timeout: 600000,
                  data: {
                      action: "InitPage",
                      txtstartdate: this.txtstartdate, //标本开始日期
                      txtenddate: this.txtenddate, //标本结束日期
                      txtreqdeptno: this.txtreqdeptno, // 申请 科室
                      txtpattype: this.txtpattype, // 病人类型
                      txtspecimencode: this.txtspecimencode, //标本类型
                      txtreqgroupid: this.txtreqgroupid, // 分单类别
                      txtwardno: this.txtwardno, // 病区
                      txtspecimentype: this.txtspecimentype, // 标本归类
                      txtemergency: this.txtemergency, // 急诊
                      infocode: this.infocode, //要查询的列数
                      infoitem: this.infoitem,
                  },
              });
              if (!!response.RData.Data) {
                  this.tableColumn = response.RData.Cols;
                  this.tableData = response.RData.Data;
                  this.xTableLoading = false;
              } else {
                  this.$message.warning("查询超时,可以尝试缩短签收日期或减少分组条件！");
                  this.xTableLoading = false;
              }
          } catch (e) {
              this.xTableLoading = false;
              this.$alert(e, "消息");
          }
      },

      rCellDblClick({ row, column }) {
          debugger;
          console.info("111====" + this.chklist.chk_req_deptno);
          if (column.property == "cp_nocnt") {
              this.selrow = row;
              if (row.uncheck_count == "0") {
                  this.$message.info("无标本明细！");
                  return false;
              }
              this.$tool
                  .request({
                      url: "LIS/LIS6/LIS623",
                      method: "post",
                      data: {
                          action: "queryreqMaster",
                          txtstartdate: this.txtstartdate, //标本开始日期
                          txtenddate: this.txtenddate, //标本结束日期
                          txtreqdeptno: this.txtreqdeptno, // 申请 科室
                          txtpattype: this.txtpattype, // 病人类型
                          txtspecimencode: this.txtspecimencode, //标本类型
                          txtreqgroupid: this.txtreqgroupid, // 分单类别
                          txtwardno: this.txtwardno, // 病区
                          txtspecimentype: this.txtspecimentype, // 标本归类
                          txtemergency: this.txtemergency == true ? "1" : "0", // 是否急诊
                          selrow: this.selrow,
                          req_deptnoflag: this.chklist.chk_req_deptno,
                          req_wardnoflag: this.chklist.chk_req_wardno,
                          pat_typecodeflag: this.chklist.chk_pat_typecode,
                          req_groupidflag: this.chklist.chk_req_groupid,
                          specimen_codeflag: this.chklist.chk_specimen_code,
                          emer_flagflag: this.chklist.chk_emer_flag,
                          yearsflag: this.chklist.chk_years,
                          monthsflag: this.chklist.chk_months,
                          daysflag: this.chklist.chk_days,
                      },
                  })
                  .then((res) => {
                      this.dialogDetailVisible = true;
                      this.reqtableColumn = res.RData.Cols;
                      this.reqtabledata = res.RData.Data;
                      this.$nextTick(() => {
                          this.$refs.reqtable.setCurrentRow(res.RData.Data[0]);
                          this.queryreqResult(res.RData.Data[0]);
                      });
                  })
                  .catch((e) => {});
          }
      },
      reqchange_Event({ row, rowIndex, column, columnIndex }, event) {
          this.queryreqResult(row);
      },
      queryreqResult(row) {
          this.$tool
              .request({
                  url: "LIS/LIS6/LIS623",
                  method: "post",
                  data: {
                      action: "queryreqDetail",
                      barcode: row.barcode,
                  },
              })
              .then((res) => {
                  this.reqdetailColumn = res.RData.Cols;
                  this.reqdetailtabledata = res.RData.Data;
              })
              .catch((e) => {});
      },

      BtnClear() {
          this.initdate();
          this.txtstartdate = this.$pub.InitDateTime(); // 生成日期
          this.txtenddate = this.$pub.InitDateTime(); //生成日期
          this.txtreqdeptno = ""; // 申请 科室
          this.txtpattype = ""; // 病人类型
          this.txtspecimencode = ""; //标本类型
          this.txtreqgroupid = ""; // 分单类别
          this.txtwardno = ""; // 病区
          this.txtspecimentype = ""; // 标本归类
          this.txtemergency = ""; // 急诊
          this.infoitem = "";
          this.infocode = "";
          this.tableData = [];
          this.tableColumn = [];
          this.chklist = {
              chk_req_deptno: false,
              chk_req_wardno: false,
              chk_pat_typecode: false,
              chk_req_groupid: false,
              chk_specimen_code: false,
              chk_emer_flag: false,
              chk_years: false,
              chk_months: false,
              chk_days: false,
          };
      },
      chkevent(e, code, name) {
          //alert(this.chkcnt);
          if (e == "1") {
              if (this.chkcnt <= 10) {
                  this.chkcnt++;
                  if (this.infocode.indexOf(code) == -1) {
                      this.infocode += code + ",";
                      this.infoitem += name + ",";
                  }
              } else {
                  this.$alert("不能选择更多的分组！", "提示");
                  this.chklist[code] = false;
                  //console.log(this, this[code]);
              }
          } else {
              if (this.infocode.indexOf(code) > -1) {
                  this.chkcnt--;
                  this.infocode = this.infocode.replace(code, "");
                  this.infoitem = this.infoitem.replace(name, "");
              }
          }
      },
      specimenChange(code, name) {
          this.txtspecimencode = code;
          this.specimenname = name;
      },
      //导出
      BtnExport() {
          let data = this.getExportData();
          let filtertxt = this.getExportFilter();
          this.$pub.exportTableExcelWithData(data, this.exportTableColLen, "LIS623  标本采样时间统计.xlsx", filtertxt, "统计条件：");
      },
      // 获取当前导出文件的所有查询条件
      getExportFilter() {
          let filtertxt = "生成时间:" + XEUtils.toDateString(this.txtstartdate, "yyyy-MM-dd") + "至" + XEUtils.toDateString(this.txtenddate, "yyyy-MM-dd") + "; ";
          if(this.txtreqdeptno) filtertxt += "科室:" + this.getOptionName(this.deptOption.filter((item) =>  ("," + this.txtreqdeptno + ",").indexOf("," + item.data + ",") > -1))+ "; ";
          if(this.txtpattype) filtertxt += "病人类型:" + this.pattypename + "; ";
          if(this.txtspecimencode) filtertxt += "标本类型:" + this.specimenname + "; ";
          if(this.txtreqgroupid) filtertxt += "分单类别:" + this.reqgroupname+ "; ";
          if(this.txtwardno) filtertxt += "病区:" + this.getOptionName(this.wardOption.filter((item) =>  ("," + this.txtwardno + ",").indexOf("," + item.data + ",") > -1))+ "; ";
          if(this.txtspecimentype) filtertxt += "标本归类:" + this.getOptionName(this.specimentypeOption.filter((item) =>  this.txtwardno == item.data))+ "; ";
          if(this.txtemergency == "1") filtertxt += "急诊; ";
          if(this.issample == "1") filtertxt += "统计类型:采样; ";
          let tatcoltxt = "";
          if(this.chklist.chk_req_deptno == "1") tatcoltxt += "申请科室、";
          if(this.chklist.chk_req_wardno == "1") tatcoltxt += "病区、";
          if(this.chklist.chk_pat_typecode == "1") tatcoltxt += "病人类型、";
          if(this.chklist.chk_req_groupid == "1") tatcoltxt += "分单类别、";
          if(this.chklist.chk_specimen_code == "1") tatcoltxt += "标本类型、";
          if(this.chklist.chk_emer_flag == "1") tatcoltxt += "急诊、";
          if(this.chklist.chk_years == "1") tatcoltxt += "年、";
          if(this.chklist.chk_months == "1") tatcoltxt += "月、";
          if(this.chklist.chk_days == "1") tatcoltxt += "日、";
          if(tatcoltxt) filtertxt += "统计项目:" + tatcoltxt.substring(0, tatcoltxt.length - 1) + "; ";
          return filtertxt;
      },
      getOptionName(option) {
          if (option && option.length > 0) {
              let optionname = "";
              option.forEach((item) => {
                  if(item.hasOwnProperty("display")) {
                      optionname += item.display + ",";
                  } else {
                      optionname += item.label + ",";
                  }
              });
              return optionname.substring(0, optionname.length - 1);
          } else {
              return "";
          }
      },
      getExportData() {
          let datas = this.$refs.xTable.afterFullData;
          let exportColumn = XEUtils.clone(this.tableColumn, true);
          exportColumn.push({ title: "标本数", field: "cp_samplecnt" });
          exportColumn.push({ title: "记录采样时间数", field: "cp_okcnt" });
          exportColumn.push({ title: "记录采样时间率", field: "cp_okrate" });
          exportColumn.push({ title: "无采样时间数", field: "cp_nocnt" });
          exportColumn.push({ title: "无采样时间率", field: "cp_norate" });
          this.exportTableColLen = exportColumn.length;
          let columns = exportColumn.filter((item) => item.field);
          let footerData = {};
          columns.forEach((item, index) => {
              if (index === 0) {
                  footerData[item.field] = "总计";
              }
              if (["cp_samplecnt", "cp_okcnt", "cp_nocnt"].includes(item.field)) {
                  footerData[item.field] = XEUtils.sum(datas, item.field);
              }
              if (["cp_okrate"].includes(item.field)) {
                  if (this.tableData.length > 0) footerData[item.field] = Number((this.SumAll(datas, "cp_okcnt") / this.SumAll(datas, "cp_samplecnt")) * 100).toFixed(2) + "%";
                  else footerData[item.field] = "0%";
              }
              if (["cp_norate"].includes(item.field)) {
                  if (this.tableData.length > 0) footerData[item.field] = Number((this.SumAll(datas, "cp_nocnt") / this.SumAll(datas, "cp_samplecnt")) * 100).toFixed(2) + "%";
                  else footerData[item.field] = "0%";
              }
          });
          datas.splice(datas.length, 0, footerData);
          let headers = [columns.map((item) => item.title)];
          return headers.concat(
              datas.map((row) => {
                  return columns.map((column) => {
                      //return this.retForamtVal(row[column.field], column.field);
                      return this.retForamtVal(row[column.field], column.field);
                  });
              })
          );
      },
      toBuffer(wbout) {
          let buf = new ArrayBuffer(wbout.length);
          let view = new Uint8Array(buf);
          for (let index = 0; index !== wbout.length; ++index) view[index] = wbout.charCodeAt(index) & 0xff;
          return buf;
      },
      //打印
      BtnPrint(index) {
          if (index == "p") {
              let column = this.$refs.xTable.getTableColumn().tableColumn;
              let str = JSON.stringify(this.$pub.InitColumn(column));
              str += "\r";
              str += JSON.stringify(this.$refs.xTable.afterFullData);
              let sql = btoa(encodeURIComponent(str));
              jsObj.PrintCustomJsonReport("5031", sql, this.userno, "标本签收统计", "");
          } else {
              // 打印样式设计
              let column = this.$refs.xTable.getTableColumn().tableColumn;
              let str = JSON.stringify(this.$pub.InitColumn(column));
              str += "\r";
              str += JSON.stringify(this.$refs.xTable.afterFullData);
              //console.log("str", str);
              let sql = btoa(encodeURIComponent(str));
              jsObj.SetCustomJsonPrintConfig("5031", sql, this.userno, "标本签收统计");
          }
      },

      formatFun({ cellValue, column, row }) {
          return this.retForamtVal(cellValue, column.property);
      },
       retForamtVal(cellValue, column) {
      //     // if (["req_deptno"].includes(column)) {
      //     //     try {
      //     //         //科室
      //     //         let deptname = this.deptOption.find((m) => m.data == cellValue);
      //     //         if (deptname != undefined && deptname != null) {
      //     //             return deptname.display;
      //     //         } else {
      //     //             return cellValue;
      //     //         }
      //     //     } catch {
      //     //         return cellValue;
      //     //     }
      //     // } else if (["req_wardno"].includes(column)) {
      //     //     //病区
      //     //     try {
      //     //         let wardname = this.wardOption.find((m) => m.data == cellValue);
      //     //         if (wardname != undefined && wardname != null) {
      //     //             return wardname.display;
      //     //         } else {
      //     //             return cellValue;
      //     //         }
      //     //     } catch {}
      //     // } else if (column == "pat_typecode") {
      //     //     try {
      //     //         let pattypename = this.pattypeOption.find((m) => m.data == cellValue);
      //     //         if (pattypename != undefined && pattypename != null) {
      //     //             return pattypename.display;
      //     //         } else {
      //     //             return cellValue;
      //     //         }
      //     //     } catch {
      //     //         return cellValue;
      //     //     }
      //     // } else if (column == "req_groupid") {
      //     //     // 分单类别
      //     //     try {
      //     //         let reqgroup = this.reqgroupOption.find((m) => m.data == cellValue);
      //     //         if (reqgroup != undefined && reqgroup != null) {
      //     //             return reqgroup.display;
      //     //         } else {
      //     //             return cellValue;
      //     //         }
      //     //     } catch {
      //     //         return cellValue;
      //     //     }
      //     // } else if (column == "specimen_code") {
      //     //     // 标本类型
      //     //     try {
      //     //         let specimen = this.specimenOption.find((m) => m.data == cellValue);
      //     //         if (specimen != undefined && specimen != null) {
      //     //             return specimen.display;
      //     //         } else {
      //     //             return cellValue;
      //     //         }
      //     //     } catch {
      //     //         return cellValue;
      //     //     }
      //     // } else
      //      if (column == "emer_flag") {
      //         if (cellValue == "1") {
      //             return "急";
      //         } else {
      //             return "";
      //         }
      //     } else {
      //         return cellValue;
      //     }
      return cellValue;
      },
      footerCellClassName({ $rowIndex, column, columnIndex }) {
          if (columnIndex === 0 || ["cp_samplecnt", "cp_okcnt", "cp_nocnt", "cp_okrate", "cp_norate"].includes(column.property)) {
              if ($rowIndex === 0) {
                  return "col-blue";
              } else {
                  return "col-red";
              }
          }
      },

      footerMethod({ columns, data }) {
          return [
              columns.map((column, columnIndex) => {
                  if (columnIndex === 0) {
                      return "总计";
                  }
                  if (["cp_samplecnt", "cp_okcnt", "cp_nocnt"].includes(column.property)) {
                      return XEUtils.sum(data, column.property);
                  }
                  if (["cp_okrate"].includes(column.property)) {
                      if (this.tableData.length > 0) return Number((this.SumAll(this.tableData, "cp_okcnt") / this.SumAll(this.tableData, "cp_samplecnt")) * 100).toFixed(2) + "%";
                      else return "0%";
                  }
                  if (["cp_norate"].includes(column.property)) {
                      if (this.tableData.length > 0) return Number((this.SumAll(this.tableData, "cp_nocnt") / this.SumAll(this.tableData, "cp_samplecnt")) * 100).toFixed(2) + "%";
                      else return "0%";
                  }
                  return null;
              }),
          ];
      },
      SumAll(data, property) {
          var plus = 0;
          if (data) {
              for (let i = 0, len = data.length; i < len; i++) {
                  plus += data[i][property] - 0;
              }
          }
          return plus;
      },
      reqgroupChange(code, name) {
          this.txtreqgroupid = code;
          this.reqgroupname = name;
      },
      seccodeChange(code, name) {
          this.txtpattype = code;
          this.pattypename = name;
      },
      BtnPrint(btype) {
          let qwhere = "日期:" + XEUtils.toDateString(this.txtstartdate, "yyyy-MM-dd") + " - " + XEUtils.toDateString(this.txtenddate, "yyyy-MM-dd");
          let qcol = this.infoitem;

          let footerData = {};
          let columns = this.$refs.xTable.getColumns();
          columns.forEach((item, index) => {
              if (index === 0) {
                  footerData[item.property] = "总计";
              }
              let resdata = this.tableData.filter((x) => {
                  return x.color != "1" && x.color != "2";
              });

              if (["cp_samplecnt", "cp_okcnt", "cp_nocnt"].includes(item.property)) {
                  footerData[item.property] = XEUtils.sum(resdata, item.property).toFixed(2);
              }

              if (["cp_okrate"].includes(item.property)) {
                  if (this.tableData.length > 0) footerData[item.property] = Number((this.SumAll(this.tableData, "cp_okcnt") / this.SumAll(this.tableData, "cp_samplecnt")) * 100).toFixed(2) + "%";
                  else footerData[item.property] = "0%";
              }
              if (["cp_norate"].includes(item.property)) {
                  if (this.tableData.length > 0) footerData[item.property] = Number((this.SumAll(this.tableData, "cp_nocnt") / this.SumAll(this.tableData, "cp_samplecnt")) * 100).toFixed(2) + "%";
                  else footerData[item.property] = "0%";
              }
          });
          let datas = XEUtils.clone(this.tableData, true);
          datas.push(footerData);
          this.$pub.PrintDynamicCol(this, "5079", datas, this.$refs.xTable.getTableColumn().tableColumn, qwhere, qcol, btype);
      },
  },
};
</Script>

<style scoped>
.pagetop {
  width: 100%;
  display: -webkit-box;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  border: solid 1px #ccc;
  position: absolute;
  z-index: 99;
  /* height: 130px;*/
  overflow-x: auto;
  overflow-x: overlay;
}

.pagecenter {
  position: absolute;
  top: 150px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.middle-center {
  position: absolute;
  height: 100%;
  left: 0px;
  right: 0px;
  overflow: auto;
}
.el-checkbox__label {
  padding: 0px;
}
.left_nav {
  width: 20%;
  height: 100%;
  border-right: 1px solid #ccc;
  padding: 0px 0px 0px 0px;
  float: left;
  display: inline;
}
.left_nav div {
  cursor: pointer;
  height: 40px;
  width: 100%;
  float: left;
  padding-left: 20px;
  line-height: 40px;
}
.left_nav .active {
  background-color: DeepSkyBlue;
}
.right_nav {
  width: 80%;
  height: 100%;
  display: inline-block;
  vertical-align: top;
  float: left;
  display: inline;
}

table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}

.table1style tr td {
  padding: 0px 2px 0px 5px;
}
::v-deep .mytable-style .vxe-footer--column.col-blue {
  color: blue !important;
  font-weight: bold;
}
::v-deep .mytable-style .vxe-body--row.row-blue {
  color: blue !important;
  font-weight: bold;
}

::v-deep .el-icon-time {
  line-height: 18px !important;
}
::v-deep .el-range__close-icon {
  line-height: 18px !important;
}
::v-deep .el-range-editor--small .el-range-separator {
  line-height: 17px !important;
}
::v-deep .mychkclass .el-checkbox {
  margin-right: 15px;
}
.operation-list {
  float: right;
  margin-right: 5px;
  margin-bottom: 5px;
}
::-webkit-scrollbar {
  width: 0px;
  height: 5px;
  border: 4px solid white;
}
::-webkit-scrollbar-thumb {
  background-color: #c1c1c1;
}
::-webkit-scrollbar-track {
  background-color: #f1f1f1;
}
/* Buttons */
::-webkit-scrollbar-button:single-button {
  background-color: #bbbbbb;
  display: block;
  border-style: solid;
  height: 5px;
  width: 5px;
}
/* Left */
::-webkit-scrollbar-button:horizontal:decrement {
  margin-right: 2px;
  border-width: 4px 4px 4px 0;
  border-color: #f1f1f1 transparent #f1f1f1 #f1f1f1;
  background-color: #000000;
}
::-webkit-scrollbar-button:horizontal:decrement:hover {
  border-color: #d2d2d2 transparent #d2d2d2 #d2d2d2;
}
/* Right */
::-webkit-scrollbar-button:horizontal:increment {
  margin-left: 2px;
  border-width: 4px 0 4px 4px;
  border-color: #f1f1f1 #f1f1f1 #f1f1f1 transparent;
  background-color: #000000;
}
::-webkit-scrollbar-button:horizontal:increment:hover {
  border-color: #d2d2d2 #d2d2d2 #d2d2d2 transparent;
}
::deep .mychkclass .el-checkbox {
  margin-top: 5px;
  margin-right: 15px;
}
</style>
